package com.cn.action;

import java.util.List;

import com.cn.entity.Stock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.service.StockService;

@Controller
public class StockAction {
	@Autowired
	private StockService stockService;

	public StockService getStockService() {
		return stockService;
	}

	public void setStockService(StockService stockService) {
		this.stockService = stockService;
	}




	// 根据搜索关键字key返回商品good的表
	// 获取：key（String）
	// 返回：List<Stock>,包括(卖家)userId(int),gameId(int),goodName,goodPrice,goodIntro,goodPicture,goodTime
	@RequestMapping("/searchStockAction")
	@ResponseBody
	public List<Stock> searchStockAction(String key) {
		System.out.println("搜索商品关键字：" + key);
		System.out.println("搜索到商品数量：" + stockService.selectStocksByKey(key).size());
		return stockService.selectStocksByKey(key);
	}


	// 买家获取商品查看信息
	// 获取:goodId(int)
	// 返回:good,包括(卖家)userId(int),gameId(int),goodName,goodPrice,goodIntro,goodPicture,goodTime
	@RequestMapping("/goodLookAction")
	@ResponseBody
	public Stock goodLookAction(int goodId) {
		System.out.println("查看商品：" + goodId);
		return stockService.lookStockByStockId(goodId);
	}

	// 购买成功:买家完成支付,商品库存-1
	// 获取:goodId(int)
	// 返回:无
	@RequestMapping("/goodSellAction")
	@ResponseBody
	public void goodSellAction(int goodId) {
		System.out.println("商品售出：" + goodId);
		stockService.sellStock(goodId);

	}



}
